$('.datatable-basic').DataTable({
	 "ajax" : {
		"url" : contextpath + "cOrder/productReportList",
		"data" : function(d) {
            var query = $("#query").serializeObject();
            query["size"] = d.length;
            query["page"] = (d.start/d.length);
			return query;
		},
		"dataFilter": function(data){
            var json = jQuery.parseJSON( data );
            json.recordsTotal = json.totalElements;
            json.recordsFiltered = json.totalElements;
            json.data = json.content;
 
            return JSON.stringify( json );
        }
	 },
	 "columns": [
         { "data": "productName" },
         { "data": "productSalePrice" },
         { "data": "operationCount" }
     ],
     "drawCallback": function( settings ) {
    	 $('.summary-datatable-basic').DataTable().draw();
      }
});

$('.parent-datatable-basic').DataTable({
	"paging": false, 
	 "ajax" : {
		"url" : contextpath + "cOrder/pproductReportList",
		"data" : function(d) {
           var query = $("#query").serializeObject();
           query["size"] = d.length;
           query["page"] = (d.start/d.length);
			return query;
		},
		"dataFilter": function(data){
           var json = jQuery.parseJSON( data );
           json.recordsTotal = json.totalElements;
           json.recordsFiltered = json.totalElements;
           json.data = json.content;

           return JSON.stringify( json );
       }
	 },
	 "columns": [
        { "data": "productName" },
        { "data": "productSalePrice" }
    ],
    "drawCallback": function( settings ) {
     }
});

$(function(){
	 
	$("#submit").click(function(){
		$('.datatable-basic').DataTable().draw();
	});

	$('select').select2({
	    minimumResultsForSearch: Infinity
	});
	
	$('#beginDate').daterangepicker(
			  { 
				  "singleDatePicker": true,
			    locale:{
			    	format: 'YYYY-MM-DD',
		            applyLabel: '确认',
		            cancelLabel: '取消',
		            fromLabel: '从',
		            toLabel: '到',
		            customRangeLabel: '选择时间',
		            daysOfWeek:["日","一","二","三","四","五","六"],
		            monthNames: ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],
		        }
			  }
			);
	 $('#beginDate').val("");
	 
	 
	 $('#endDate').daterangepicker(
			  { 
				  "singleDatePicker": true,
			    locale:{
			    	format: 'YYYY-MM-DD',
		            applyLabel: '确认',
		            cancelLabel: '取消',
		            fromLabel: '从',
		            toLabel: '到',
		            customRangeLabel: '选择时间',
		            daysOfWeek:["日","一","二","三","四","五","六"],
		            monthNames: ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],
		        }
			  }
			);
	 $('#endDate').val("");
})

function sortA(){
	var i = parseInt($("#sort").val());
	if(i == 1){$("#sort").val(2)}
	if(i != 1){$("#sort").val(1)}
	
	$('.datatable-basic').DataTable().draw();
}

function sortB(){
	var i = parseInt($("#sort").val());
	if(i == 3){$("#sort").val(4)}
	if(i != 3){$("#sort").val(3)}
	
	$('.datatable-basic').DataTable().draw();
}
